<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <script src="${BasePath}/weixin/js/mui.min.js"></script>
    <link href="${BasePath}/weixin/css/mui.min.css" rel="stylesheet"/>
    <link href="${BasePath}/weixin/css/mui-color.css" rel="stylesheet"/>
     <link href="${BasePath}/weixin/css/mui-font.css" rel="stylesheet"/>
     <link href="${BasePath}/weixin/fonts/font-awesome.min.css" rel="stylesheet"/>
     <link href="${BasePath}/weixin/css/common.css" rel="stylesheet"/>
	<script src="${BasePath}/weixin/js/jquery.js"></script>
	<style>
     	html,body{    height: 100%;
    overflow: hidden;
    background-color: #fff;}
    .mui-content{background-color: #fff;}
     </style>
    <script type="text/javascript" charset="utf-8">
      	mui.init();
    </script>
</head>
<body>
	<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left ft-c-g fs-20"></a>
			<!--左边字-->
			<span class=" ft-c-b fs-16 back-name">帐户密码登录</span>
		</header>
		<div class="mui-content" style="margin-top: 3em;">
			<!--输入密码-->
			
				
			
				<form class="mui-input-group" style="font-size: 1em;">
					<div class="mui-input-row">
						<label><span class="fa fa-mobile-phone  ft-c-c2 mg-r"></span>手机号</label>
						<input id="username" type="number" class="mui-input-clear" placeholder="请输入手机号" required="required">
					</div>
				    <div class="mui-input-row">
						<label><span class="fa fa-lock  ft-c-c2 mg-r"></span>密码</label>
						<input id="password" type="password" class="mui-input-clear" placeholder="请输入密码" required="required">
					</div>
				</form>
				<div class="mui-text-center mg-l mg-r deposit-warn" >
					<div class="mui-text-left fs-14 ft-c-g  mg-b ">注：注册请下载App</div>
				</div>
				<div  class="rm-list">
				<div class="rm-list mui-text-center mg-l mg-r deposit-warn " >
					<button id="login" class="clear mui-btn mui-btn-yellow mui-btn-block mui-btn-outlined" style="padding: 0.625em 1.25em;">立即登录</button>
				</div>
			 </div>	
			</div>
		</div>
	<script>

		// $(function(){
         //    var member = window.localStorage.memberEntity;
         //    console.log('memberEntity=' + member);
         //    var memberId = JSON.parse(member).id;
         //    console.log('memberId=' + memberId);
         //    if(member != null){
         //        var param = {
         //            memberId:memberId
		// 		}
         //        var result = autoLogin(param);
         //        if(result){
         //            //window.location.href = "${BasePath}/page/weixin/recharge";
         //        }
		// 	}
		// });

        $(function(){
            $.ajax({
                type: 'get',
                cache:false,
                async:false,
                url: "${BasePath}/signout",
                data: "",
                dataType: "json",
                success: function(data){
                    console.log(data);
                },
                error: function(request) {
                    //console.log(request);
                    //prompt($(".prompt"), "系统繁忙，请稍候重试！");
                }
            });

            var adminstorage=window.localStorage;
            adminstorage.removeItem("WEIXIN-ACCESS-TOKEN");//清除c的值
        });

        $("#login").click(function(){
            var username = $("#username").val();
            var password = $("#password").val();

            console.log('username=' + username);
            console.log('password=' + password);

            if(username == ''){
                alert('请输入用户名！');
                return;
            }

            if(password == ''){
                alert('请输入密码！');
                return;
            }

            //验证用户名和密码
            var userInfo = {
                username: username+"&weixin",
                password: password
            };

            var loginResult = login(userInfo);
            console.log(loginResult);
            if(loginResult){

                if(!window.localStorage){
                    prompt($(".prompt"), '"浏览器需要支持localstorage"');
                    return ;
                }else{
                    var storage=window.localStorage;
                    //写入access_token字段
                    console.log(loginResult.access_token);
                    storage.setItem("WEIXIN-ACCESS-TOKEN",loginResult.access_token);
                    console.log(document.referrer);
                    if (document.referrer === '' || document.referrer == '${BasePath}/page/weixin/') {
                        window.location.href = "${BasePath}/page/weixin/recharge";
                    } else {
                        window.location.href = document.referrer;
                    }
                }

            }
            else{
                alert("用户名或密码错误！");
                return;
            }
        });

        function login(user){
            var ret = false;
            console.log("login user:" + JSON.stringify(user));
            $.ajax({
                type: 'post',
                cache:false,
                async:false,
                url: "${BasePath}/page/login",
                data: user,
                dataType: "json",
                success: function(data){
                    console.log("login data:" + JSON.stringify(data));
                    //写入localStorage
                    // window.localStorage.setItem("memberEntity",JSON.stringify(data.result));
                    ret = data;
                },
                error: function(request) {
                    prompt($(".prompt"), "系统繁忙，请稍候重试！");
                }
            });
            return ret;
        }
        function autoLogin(user){
            var ret = false;
            console.log("login user:" + JSON.stringify(user));
            $.ajax({
                type: 'post',
                cache:false,
                async:false,
                url: "${BasePath}/page/weixin/autoLogin",
                data: user,
                dataType: "json",
                success: function(data){
                    console.log("login data:" + JSON.stringify(data));
                    ret = data.result;
                },
                error: function(request) {
                    prompt($(".prompt"), "系统繁忙，请稍候重试！");
                }
            });
            return ret;

        }
	</script>
</body>
</html>